﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LightProbeCtrl : MonoBehaviour
{
    public LightProbes targetLightProbes;
    public bool active;
    LightProbes cache;
    // Start is called before the first frame update
    void OnEnable()
    {
        
        StartCoroutine(ToogleLightProbes());
    }

    
    IEnumerator ToogleLightProbes()
    {
        while (true)
        {
            yield return new WaitUntil(() => active);
            if(cache==null)
            cache = LightmapSettings.lightProbes;
           // Debug.LogError("active " + LightmapSettings.lightProbes.GetInstanceID() + " " + cache.GetInstanceID() + " " + targetLightProbes.GetInstanceID());
            LightmapSettings.lightProbes = targetLightProbes;
            yield return new WaitUntil(() => !active);
           // Debug.LogError("disactive " + LightmapSettings.lightProbes.GetInstanceID() + " " + cache.GetInstanceID() + " " + targetLightProbes.GetInstanceID());
            LightmapSettings.lightProbes = cache;
        }
    }

    public void ResetLight()
    {
        LightmapSettings.lightProbes = cache;
        active = false;
    }
    //private void OnDestroy()
    //{
    //    LightmapSettings.lightProbes = cache;
    //    active = false;
    //}
}
